/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 * \file
 * \brief Implementation for datatypes.
 * \author Antti Maula <antti.maula@tkk.fi>
 *
 */

#include "MaCI_AlarmDataTypes.hpp"
#include "settings.hpp"
#include <stdio.h>

//*****************************************************************************

SEventsDisplayConfiguration::SEventsDisplayConfiguration(void)
  : isLimitEventsEnabled(false),
    eventLimit(1000),
    enabledEvents(0xFF),
    isQuestionPopupEnabled(true),
    isAckPopupEnabled(true)
{
}
//*****************************************************************************

bool SEventsDisplayConfiguration::SaveXMLFile(const std::string &aXmlFilename, 
                                              const std::string &aRootKey)
{
  bool result = false;

  gim::CSettings s;
  s.SetValue(aRootKey+".isLimitEventsEnabled", isLimitEventsEnabled);
  s.SetValue(aRootKey+".eventLimit", eventLimit);
  s.SetValue(aRootKey+".enabledEvents", enabledEvents);
  s.SetValue(aRootKey+".isQuestionPopupEnabled", isQuestionPopupEnabled);
  s.SetValue(aRootKey+".isAckPopupEnabled", isAckPopupEnabled);
  result = s.WriteSettingsXMLFile(aXmlFilename);

  return result;
}
//*****************************************************************************

bool SEventsDisplayConfiguration::LoadXMLFile(const std::string &aXmlFilename,
                                              const std::string &aRootKey)
{
  bool result = false;
  gim::CSettings s;
  if (s.ReadSettingsXMLFile(aXmlFilename)) {
    int t;

    s.SetBaseKey(aRootKey);

    // Is enabled?
    if (s.GetValue("isLimitEventsEnabled", t)) {
      isLimitEventsEnabled = (t != 0);
    }

    // Limit?
    if (s.GetValue("eventLimit", t)) {
      eventLimit = t;
    }

    // Event Enables?
    if (s.GetValue("enabledEvents", t)) {
      enabledEvents = t;
    }

    // Action Enables?
    if (s.GetValue("isQuestionPopupEnabled", t)) {
      isQuestionPopupEnabled = t;
    }
    if (s.GetValue("isAckPopupEnabled", t)) {
      isAckPopupEnabled = t;
    }
  }

  return result;
}
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
